package pzl.kt.study.base

//任何实现了iterator接口的，hasNext、next操作符函数，都可遍历
class CustomBean : Iterator<String> {

    private var beans = ArrayList<String>()

    private var index = -1

    public fun add(bean: String) {
        beans.add(bean)
        index++
    }

    //必实现
    public operator fun iterator(): CustomBean {
        return this
    }

    //必实现
    public override operator fun hasNext(): Boolean {
        if (index >= 0) return true
        return false
    }

    //必实现
    public override operator fun next(): String {
        var value = beans.get(index)
        index--
        return value
    }


}